package com.own.component.store.core.confirm.aspect;

import com.own.component.store.core.confirm.aop.ConfirmAop;
import com.own.component.store.core.confirm.util.RequestConfirmUtil;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * ConfirmAspect
 *
 * @author chenxueli
 * @date 2020/12/9 10:32
 */
@Slf4j
@Aspect
@Component
@Order(2)
@ConditionalOnProperty(prefix = "own.store.confirm", name = "enable", havingValue = "true", matchIfMissing = true)
public class ConfirmAspect {

    @Resource
    private RequestConfirmUtil requestConfirmUtil;

    @Pointcut("@annotation(com.own.component.store.core.confirm.aop.ConfirmAop)")
    public void aspect() {
    }

    @Before("aspect() && @annotation(confirmAop)")
    public void doBefore(JoinPoint point, ConfirmAop confirmAop) {
        requestConfirmUtil.check(confirmAop);
    }

}
